#include<bits/stdc++.h>
#define rep(i,a,b) for(int i(a);i<=(b);++i)
#define req(i,a,b) for(int i(a);i>=(b);--i)
using namespace std;
char buf[1<<23],*p1=buf,*p2=buf;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template<typename TP> inline TP read(TP &num)
{
	TP x=0;
	int f=0;
	char ch=getchar();
	while(ch<48||ch>57) f|=ch=='-',ch=getchar();
	while(48<=ch&&ch<=57) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return num=f?-x:x;
}
template<typename ...Args> inline void read(Args &...args)
{
	(read(args),...);
}
template<typename TP> inline void write(TP x)
{
	(x<0)?(putchar('-'),x=-x):0;
	(x>9)?(write(x/10),0):0;
	putchar((x%10)^48);
}
template<typename TP> inline void writeln(TP x)
{
	write<TP>(x);
	puts("");
}
int n,f[21],ans;
signed main()
{
	freopen("a.in","r",stdin);
	freopen("a.out","w",stdout);
	read(n);
	rep(i,1,n) read(f[i]);
	rep(st,0,(1<<(n+1))-1)
	{
		vector<int> v;
		rep(i,0,n) if((st>>i)&1) v.push_back(i);
		int cnt=0;
		while(!v.empty())
		{
			vector<int> nv,mp(21,0);
			for(auto p:v)
			{
				if(!p) ++cnt;
				else ++mp[f[p]];
			}
			rep(ps,0,20) if(mp[ps]==1) nv.push_back(ps);
			v.swap(nv);
		}
		ans+=cnt;
	}
	writeln(ans);
	return 0;
}
